<?php

namespace common\widgets\grid;

use yii\helpers\Html;
use yii\grid\GridView as BaseGridView;

/**
 * The GridView widget is used to display data in a grid.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
class DataTableGridView extends BaseGridView {

    /**
     * 
     * <div class="caption">
     * 		<i class=" icon-layers font-green"></i>
     * 		<span class="caption-subject font-green sbold uppercase">Validation States</span>                      
     * </div>
     * <div class="actions">
     * 		<a class="btn btn-circle btn-icon-only btn-default" href="javascript:;"><i class="icon-cloud-upload"></i></a>
     * 		<a class="btn btn-circle btn-icon-only btn-default" href="javascript:;"><i class="icon-wrench"></i></a>
     * 		<a class="btn btn-circle btn-icon-only btn-default" href="javascript:;"><i class="icon-trash"></i></a>
     * </div>
     * 
     * @var type 
     */
    public $portletTitle;

    /**
     * @var array the HTML attributes for the portletTitle element.
     * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
     * @see portletTitle
     */
    public $portletTitleOptions = ['class' => 'portlet-title'];

    /**
     * @var array the HTML attributes for the grid table element.
     * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
     */
    public $tableOptions = ['class' => 'table table-light'];

    /**
     * @var array the HTML attributes for the container tag of the grid view.
     * The "tag" element specifies the tag name of the container element and defaults to "div".
     * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
     */
    //public $options = ['class' => 'portlet light portlet-fit bordered'];

    /**
     * @var boolean whether to show the header section of the grid table.
     */
    public $showHeader = true;

    /**
     * @var boolean whether to show the footer section of the grid table.
     */
    public $showFooter = false;

    /**
     * @var boolean whether to show the grid view if [[dataProvider]] returns no data.
     */
    public $showOnEmpty = true;

    /**
     * @var string the HTML display when the content of a cell is empty.
     * This property is used to render cells that have no defined content,
     * e.g. empty footer or filter cells.
     *
     * Note that this is not used by the [[DataColumn]] if a data item is `null`. In that case
     * the [[\yii\i18n\Formatter::nullDisplay|nullDisplay]] property of the [[formatter]] will
     * be used to indicate an empty data value.
     */
    public $emptyCell = '&nbsp;';

    /**
     * @var array the options for rendering the filter error summary.
     * Please refer to [[Html::errorSummary()]] for more details about how to specify the options.
     * @see renderErrors()
     */
    public $filterErrorSummaryOptions = ['class' => 'error-summary'];

    /**
     * @var array the options for rendering every filter error message.
     * This is mainly used by [[Html::error()]] when rendering an error message next to every filter input field.
     */
    public $filterErrorOptions = ['class' => 'help-block'];

    /**
     * @var string the layout that determines how different sections of the list view should be organized.
     * The following tokens will be replaced with the corresponding section contents:
     *
     * - `{summary}`: the summary section. See [[renderSummary()]].
     * - `{errors}`: the filter model error summary. See [[renderErrors()]].
     * - `{items}`: the list items. See [[renderItems()]].
     * - `{sorter}`: the sorter. See [[renderSorter()]].
     * - `{pager}`: the pager. See [[renderPager()]].
     */
    public $layout = '<div class="table-scrollable">{items}</div>{summary}{pager}';

    /**
     * Initializes the grid view.
     * This method will initialize required property values and instantiate [[columns]] objects.
     */
    public function init() {
        $this->renderPortletLayout();
        Html::addCssClass($this->tableOptions, 'table table-light');
        parent::init();
    }

    /**
     * Renders the portletLayout element.
     * This method will set layout 'portlet'.
     */
    public function renderPortletLayout() {
        if (!empty($this->portletTitle)) {
            $this->layout = Html::tag('div', $this->portletTitle, $this->portletTitleOptions) . $this->layout;
        }
    }

}
